package com.xbh.management.service;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xbh.common.utils.JwtUtil;
import com.xbh.management.mapper.AttendanceMapper;
import com.xbh.management.model.ManAttendance;
import com.xbh.management.model.ManLeave;
import org.aspectj.weaver.ast.Var;
import org.springframework.stereotype.Service;

/**
 * @program: management-center
 * @description:
 * @author: 许宝华
 * @create: 2022-03-08 14:21
 */

@Service
public class AttendanceServiceImpl extends ServiceImpl<AttendanceMapper, ManAttendance> implements AttendanceService {
    @Override
    public boolean saveAttendance(ManAttendance manAttendance) {
        manAttendance.setUserId(JwtUtil.getUserId());
        manAttendance.setUsername(JwtUtil.getUsername());
        manAttendance.setCreatePerson(JwtUtil.getUsername());
        manAttendance.setUpdatePerson(JwtUtil.getUsername());
        int insert = this.baseMapper.insert(manAttendance);
        if(insert > 0){
            return true;
        }
        return false;
    }

    @Override
    public Page<ManAttendance> list(Page<ManAttendance> page, ManAttendance manAttendance) {
        LambdaQueryWrapper<ManAttendance> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ManAttendance::getDeleted,new Integer(0));
        wrapper.eq(ManAttendance::getUserId,JwtUtil.getUserId());
        wrapper.orderByDesc(ManAttendance::getCreateTime);
        if(StrUtil.isNotEmpty(manAttendance.getUsername())){
            wrapper.like(ManAttendance::getUsername,manAttendance.getUsername());
        }
        return this.baseMapper.selectPage(page,wrapper);
    }
}
